home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Processor Fault!!??
- Date: 28 Jan 1996 16:49:09 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Jan28094909@qcd.lanl.gov>
- References: <Pine.A32.3.91j.960128010358.43648E-100000@homer23.u.washington.edu>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: "Q. Sun"'s message of Sun, 28 Jan 1996 01:13:18 -0800
-
- In article
- <Pine.A32.3.91j.960128010358.43648E-100000@homer23.u.washington.edu>
- "Q. Sun" <quanger@u.washington.edu> writes:
- <snip>
- I was doing some examples off a text we are using and I am having
- problems with it. The chapter is on arrays and I type in and ran the
- programs in the text. When I ran it using Turbo C++ 3.1 it gave a nasty
- General Protection Fault and stating it's the processor's fault! It also
- said things like "0x211F:0x00BE Processor Fault." In Windows 95 it total
- crashed! But in Windows for Workgroups 3.11, it recovered a
- couple of runs until it eventually kicked me out to DOS.
-
- I'm running a Pentium 120 with 16megs of RAM. Do I have one of those old
- faulty Pentiums? My system is about one week new.
-
- The most common errors are programming errors: even on faulty
- processors, it is rare that you discover a fault so easily. What you
- have to realize is that the compiler interprets what you wrote in your
- C source and converts what _it_ understood to `machine code'. It is
- very easy to write source code that the compiler cannot understand: in
- such cases, the compiler will tell you that. On the other hand,
- sometimes you can write code which violates _assumptions_ which
- compilers make about what you are doing, and which it doesn't
- specifically check for. In such cases, you will get no warning, but
- the compiled machine code could be completely meaningless. Called upon
- to do such meaningless tasks, a processor could easily `fault': That
- is no fault of the processor :-)
-
-
- The code example is EXACTLY as follows:
- <snip>
- main ()
-
- This is completely unrelated, but defaulting the return type of a
- function is not good style. You should write `int main()' at least,
- and `int main(void)' or `int main(int argc, char*argv[])' are the
- preferred forms.
-
- <snip>
- int number_to_convert;
- <snip>
- scanf ("%ld", &number_to_convert);
-
- This is a problem. You are telling the compiler to pass the format
- string %ld and the address of number_to_convert to scanf. A compiler
- is not required to check that the format string matches the variable
- that you are trying to fill: it just assumes you know what you are
- doing. %ld instructs scanf to fill a _long_ variable, not an _int_
- variable.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-